package com.example.controller.institutioncare.safetyinformation;

import com.example.bean.institutioncare.safetyinformation.SafetyManagement;
import com.example.bean.institutioncare.safetyinformation.SafetyManagementVo;
import com.example.service.institutioncare.institutionadmin.BasicService;
import com.example.service.institutioncare.safetyinformation.SafetyService;
import com.example.utils.Resss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 机构养老/安全信息管理/安全教育与培训记录
 * */
@CrossOrigin
@RestController
@RequestMapping("/safetymana")
public class SafetyController{

    @Autowired
    SafetyService safetyService;
    @Autowired
    BasicService basicService;

    @PostMapping("/selectPageInfo")
    public Resss selectPageInfo(@RequestBody SafetyManagementVo vo){
        return new Resss().data("safety",safetyService.selectPageInfo(vo)).data("sssd",basicService.selectInfo());
    }

    @PostMapping("/addSafetyMana")
    public Resss addPost(@RequestBody SafetyManagement safetyMan){
        if(safetyMan.getPertypes()==null){
            return new Resss().code(safetyService.addSafetyMana(safetyMan));
        }
        return new Resss().code(safetyService.addSafetyMana(xun(safetyMan)));
    }

    /**安全教育与培训记录*/
    @PostMapping("/updaSafetyMana")
    public Resss updaSafetyMana(@RequestBody SafetyManagement safetyMan){
        return new Resss().code(safetyService.updaSafetyMana(xun(safetyMan)));
    }

    /**安全标识检查记录*/
    @PostMapping("/updaSafetyManana")
    public Resss updaSafetyManana(@RequestBody SafetyManagement safetyMan){
        return new Resss().code(safetyService.updaSafetyManana(safetyMan));
    }

    /**每月防火检查记录*/
    @PostMapping("/updaSafetyManaaa")
    public Resss updaSafetyManaaa(@RequestBody SafetyManagement safetyMan){
        return new Resss().code(safetyService.updaSafetyManaaa(safetyMan));
    }

    /**维护保养和检测记录*/
    @PostMapping("/updaSafetywei")
    public Resss updaSafetywei(@RequestBody SafetyManagement safetyMan){
        return new Resss().code(safetyService.updaSafetywei(safetyMan));
    }

    /**安全演练记录*/
    @PostMapping("/updaSafetyNanana")
    public Resss updaSafetyNanana(@RequestBody SafetyManagement safetyMan){
        return new Resss().code(safetyService.updaSafetyNanana(safetyMan));
    }

    @DeleteMapping("/delete/{noid}")
    public Resss delete(@PathVariable("noid")String noid){
        return new Resss().code(safetyService.delete(noid));
    }

    public SafetyManagement xun(SafetyManagement safetyMan){
        String rrr="";
        for(String sss:safetyMan.getPertypes()){
            rrr+=sss+",";
        }
        safetyMan.setPertype(rrr);
        return safetyMan;
    }
}